import org.junit.Test;
import org.learn.spring5.User;
import org.learn.spring5.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.lang.Nullable;

public class TestSpring5 {


    /**
     * Spring5整合log4j2
     */
    @Test
    public void testAccount() {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        UserService userService = context.getBean("userServiceImpl", UserService.class);
        userService.transferAccount();//转账操作

    }

    @Test
    public void test2() {
        //1.手动实例化对象
        User user = new User();
        //2.创建GenericApplicationContext对象
        GenericApplicationContext context = new GenericApplicationContext();
        context.refresh();
        //3.调用context的registerBean方法注册对象
        context.registerBean("user1", User.class, () -> new User());
        User bean = (User) context.getBean("user1");
        System.out.println(bean);

    }

}
